Skip to main content
Glama

Gitlab Create MR Comment Tool

Add comments to merge requests in GitLab projects to streamline code review and collaboration. Specify project ID, merge request ID, and comment content for effective feedback.

Instructions

为指定项目的合并请求添加评论。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commentYes评论内容
fieldsNo需要返回的字段路径数组
mergeRequestIdYes合并请求 ID
projectIdYes项目 ID

Implementation Reference

  • The `execute` method implementing the tool's core logic: resolves project ID, makes POST request to GitLab API to create MR comment, filters response if fields specified, handles errors.
    async execute(args: unknown, context: Context<Record<string, unknown> | undefined>) { const typedArgs = args as { projectId: string | number; mergeRequestId: number; comment: string; fields?: string[]; }; const { projectId: projectIdOrName, mergeRequestId, comment, fields } = typedArgs; try { const client = createGitlabClientFromContext(context); const resolvedProjectId = await client.resolveProjectId(projectIdOrName); if (!resolvedProjectId) { throw new Error(`无法解析项目 ID 或名称:${projectIdOrName}`); } const endpoint = `/projects/${encodeURIComponent(String(resolvedProjectId))}/merge_requests/${mergeRequestId}/notes`; const response = await client.apiRequest(endpoint, "POST", undefined, { body: comment }); if (!client.isValidResponse(response)) { throw new Error(`GitLab API error: ${response?.message || 'Unknown error'}`); } if (fields) { const filteredResponse = filterResponseFields(response, fields); return { content: [{ type: "text", text: JSON.stringify(filteredResponse) }] } as ContentResult; } return { content: [{ type: "text", text: JSON.stringify(response) }] } as ContentResult; } catch (error: any) { return { content: [ { type: "text", text: `GitLab MCP 工具调用异常:${error?.message || String(error)}` } ], isError: true }; } }
  • Zod schema defining the input parameters: projectId (string|number), mergeRequestId (number), comment (string), optional fields (string[]).
    parameters: z.object({ projectId: z.union([z.string(), z.number()]).describe("项目 ID 或名称"), mergeRequestId: z.number().describe("合并请求 ID"), comment: z.string().describe("评论内容"), fields: z.array(z.string()).optional().describe("需要返回的字段路径数组"), }),
  • The `fastmcpTools` array including GitlabCreateMRCommentTool, used for registration.
    const fastmcpTools = [ GitlabAcceptMRTool, GitlabCreateMRCommentTool, GitlabCreateMRTool, GitlabGetUserTasksTool, GitlabRawApiTool, GitlabSearchProjectDetailsTool, GitlabSearchUserProjectsTool, GitlabUpdateMRTool, ];
  • The registration loop in `registerGitLabToolsForFastMCP` that calls `server.addTool(tool)` for filtered tools.
    fastmcpTools.forEach(tool => { const standardizedName = toolNameMapping[tool.name as keyof typeof toolNameMapping]; if (shouldRegisterTool(standardizedName as GitLabToolName, options.toolFilter)) { // GitLabTool is now fully compatible with FastMCP's base type, can be registered directly server.addTool(tool); } });
  • Tool name mapping from internal name to standardized name used in filtering.
    [GitlabCreateMRCommentTool.name]: "Gitlab_Create_MR_Comment_Tool",

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ZephyrDeng/mcp-server-gitlab'

If you have feedback or need assistance with the MCP directory API, please join our Discord server